package lab03.test08;

        import java.io.FileInputStream;
        import java.io.FileNotFoundException;
        import java.io.FileOutputStream;
        import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        String file1="D:\\file1.txt";
        String file2="D:\\file2.txt";
        String file3="D:\\file3.txt";
        FileInputStream file1InputStream=null;
        FileInputStream file2InputStream=null;
        FileOutputStream file3OutputStream=null;
        try {
            file1InputStream=new FileInputStream(file1);
            file2InputStream=new FileInputStream(file2);
            file3OutputStream=new FileOutputStream(file3);
            int data1=0;
            int data2=0;
            while (((data1=file1InputStream.read())!=-1)||((data2=file2InputStream.read())!=-1)){
                file3OutputStream.write(data1);
                file3OutputStream.write(data2);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                file1InputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                file2InputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                file3OutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
